package com.example.cinema;

import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;
import android.widget.ListAdapter;
import android.widget.ListView;

import java.util.List;

public class CountListHeight {
    

    private ListView listView;

    public CountListHeight( ListView listView) {

        this.listView = listView;
        setheight();
    }

    private void setheight() {
        ListAdapter adapter = listView.getAdapter();
        if(adapter==null)
        {
            return;
        }

        int total = 0;
        for (int s=0;s<adapter.getCount();s++)
        {
            View itemview = adapter.getView(s,null,listView);
            itemview.measure(0,0);
            total+= itemview.getMeasuredHeight();
        }
        ViewGroup.LayoutParams params = listView.getLayoutParams();
        params.height = total;
        listView.setLayoutParams(params);
        Log.i("KKKK",total+"");
    }
}
